unit uGlobal;

interface

uses
  Windows, Messages;

const
  WM_IMMESSAGE      = WM_USER + 100;
  
  IM_DEBUGOUT       = 1;
  IM_NEW_TASK       = 2;
  IM_TASK_COMPLEATE = 3;

type
  TIMMessage = record
    Param: Integer;
    Tag: Integer;
    Series: integer;
    BufLen: Integer;
    Buf: PChar;
  end;
  PIMMessage = ^TIMMessage;

procedure DebugOut(const msg: string);
procedure SendIMMsg(ident: Word; param, tag, series: Integer; msg: string=''); overload;
procedure SendIMMsg(ident: Word; param, tag, series: Integer; buf: Pchar; bufLen: Integer); overload;

var
  G_DebugHandle: THandle = 0;
  
implementation

procedure DebugOut(const msg: string);
begin
  SendIMMsg(IM_DEBUGOUT, 0, 0, 0, msg);
end;

procedure SendIMMsg(ident: Word; param, tag, series: Integer; msg: string);
begin
  SendIMMsg(ident, param, tag, series, PChar(msg), Length(msg));
end;

procedure SendIMMsg(ident: Word; param, tag, series: Integer; buf: Pchar; bufLen: Integer);
var
  p: PIMMessage;
begin
  if G_DebugHandle<>0 then
  begin
    New(p);
    FillChar(p^, SizeOf(TIMMessage), 0);
    p.Param := param;
    p.Tag := tag;
    p.Series := series;
    p.BufLen := bufLen;
    if bufLen>0 then
    begin
      GetMem(p.Buf, bufLen + 1);
      Move(buf^, p.buf^, bufLen);
      p.Buf[bufLen] := #0;
    end;
    PostMessage(G_DebugHandle, WM_IMMESSAGE, ident, Integer(p));
  end;
end;

end.
